# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=tg
pkgver=1.3.1
pkgrel=13
_tglver=2.0.1
_tlparserver=0_git20151118
pkgdesc="Command line Telegram client"
url="https://github.com/vysheng/tg"
arch="all !s390x !mips !mips64"
license="GPL-3.0"
depends_dev="readline-dev openssl-dev libconfig-dev libevent-dev jansson-dev lua5.3-dev"
makedepends="$depends_dev zlib-dev grep"
provides="telegram-cli"
source="$pkgname-$pkgver.tar.gz::https://github.com/vysheng/tg/archive/$pkgver.tar.gz
	tgl-$_tglver.tar.gz::https://github.com/vysheng/tgl/archive/$_tglver.tar.gz
	https://dev.alpinelinux.org/archive/tl-parser/tl-parser-$_tlparserver.tar.gz

	makefile-tl-parser-nocrc32.patch
	musl-include-fix.patch
	makefile-remove-werror.patch
	openssl-1.1.patch
	"
#	tgl-openssl-1.1.patch::https://github.com/vysheng/tgl/pull/126/commits/66758bbea27515c5f35e3fafc64d3a3601a5b777.patch
pkgusers="telegram"
pkggroups="telegram"
builddir="$srcdir/$pkgname-$pkgver"

prepare() {
	cd "$builddir"
	mv "$srcdir"/tg-$_tlparserver/* "$srcdir/tgl-$_tglver/tl-parser"
	mv "$srcdir"/tgl-$_tglver/* "$srcdir/tg-$pkgver/tgl"

	default_prepare
}

build() {
	cd "$builddir"

	export LUA=/usr/bin/lua5.3
	export LUA_INCLUDE=-I/usr/include/lua5.3
	export LUA_LIB=$(pkg-config --libs lua5.3)
	./configure \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		--enable-libconfig \
		--enable-liblua
	make
}

package() {
	cd "$builddir"

	install -D bin/telegram-cli \
		"$pkgdir"/usr/bin/telegram-cli
	install -D tg-server.pub \
		"$pkgdir"/etc/telegram-cli/tg.pub
}

sha512sums="ac8341e8f951922fa78a1db74d9b1a87b03c3339307bd9c46da71656d8d6e55bf0b546abba1638ae01843341a4d2134b6ab244e15547e8806d74b21ac1306114  tg-1.3.1.tar.gz
5d16a0e9c6e63ce91238501520e7699164298d9e6e275d8b90da675cca6d0b09944888d95320482e8e232d1bd540dbe80cfe58ac7d70f3157a4372c7fd550366  tgl-2.0.1.tar.gz
a7f16bd2cdedf62a1dbd180fcf957850d3b1c1c08b99f4f389ef5a83e228eb773e5da84e3127455880f4ebb526787bdae097200b337ae6df74b50bebec7c92fe  tl-parser-0_git20151118.tar.gz
b61e5907c6cf035ce067cfbc19995a04afa1f04cef00be52a02943e850d4a2754dba67732fa6ca958f2e48a741b2048fb38652c17b73e46359c550257e563f42  makefile-tl-parser-nocrc32.patch
4e26e7421db48b7074197e4cea1c6a6fce33a2b259f0da0e378f9a83f115e961016586b63d960d491cb5c4866fffbf454a5e0eda47ad16b3b77d117c8508f1f2  musl-include-fix.patch
1f8fab90948079abc94169751851347a6753dc13cf19973ba05a6f533ac173ba6ce70863988f2b167c27a347f4aeaa710c70cc960c0ba4090c43461386f8b217  makefile-remove-werror.patch
46ada5490a7db962aa70b73fe867f737a852fa5fcad331d9221afaae93e0bb2f0129568bb9c9eb337fad3ead8935b5eb5262e87d156411f12860aa1e740d5b39  openssl-1.1.patch"
